﻿@{
	Layout = null;
}

<!DOCTYPE html>

<html>
<head>
	<meta name="viewport" content="width=device-width" />
	<title>Index</title>
	<link href="~/Content/Css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
	<link href="~/Content/Css/font-awesome.css?v=4.4.0" rel="stylesheet">
	<link href="~/Content/Css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
	<link href="~/Content/Css/animate.css" rel="stylesheet">
	<link href="~/Content/Css/style.css?v=4.1.0" rel="stylesheet">
	<style type="text/css">
		.custom-box { margin-bottom:8px;}
	</style>
</head>
<body>
	<div class="wrapper wrapper-content animated fadeInRight">
		<div class="row row-lg custom-box">
			<div class="col-sm-10">
				<div class="btn-group">
					<button id="insertBtn" type="button" class="btn btn-outline btn-default">
						<i class="glyphicon glyphicon-plus" aria-hidden="true"></i>
					</button>
					<button id="editBtn" type="button" class="btn btn-outline btn-default">
						<i class="glyphicon glyphicon-edit" aria-hidden="true"></i>
					</button>
					<button id="deleteBtn" type="button" class="btn btn-outline btn-default">
						<i class="glyphicon glyphicon-trash" aria-hidden="true"></i>
					</button>
					<button id="refreshBtn" type="button" class="btn btn-outline btn-default">
						<i class="glyphicon glyphicon-refresh" aria-hidden="true"></i>
					</button>
				</div>
			</div>
		</div>
		<div class="row row-lg">
			<div class="col-sm-12">
				<table id="table"></table>
			</div>
		</div>
	</div>

	<!-- 全局js -->
	<script type="text/javascript" src="~/Scripts/jquery.min.js?v=2.1.4"></script>
	<script type="text/javascript" src="~/Scripts/bootstrap.min.js?v=3.3.6"></script>
	<!-- 自定义js -->
	<script type="text/javascript" src="~/Scripts/content.js?v=1.0.0"></script>
	<script type="text/javascript" src="~/Scripts/common.js"></script>
	<!-- Bootstrap table -->
	<script type="text/javascript" src="~/Scripts/plugins/bootstrap-table/bootstrap-table.min.js"></script>
	<script type="text/javascript" src="~/Scripts/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
	<!-- layer javascript -->
	<script type="text/javascript" src="~/Scripts/plugins/layer/layer.min.js"></script>

	<script type="text/javascript">
		var staffId = "@ViewBag.staffId";
		var $table = $("#table");

		//初始化Table
		var url = "/organization/staff/loginasync?staffid=" + staffId;
		var columns = [
			{ field: "selected", width: 38, checkbox: true, },
			{ title: "行号", width: 60, align: "center", formatter: function (value, row, index) { return index + 1; } },
			{ field: "loginType", title: "登录类别", width: 60, align: "center" },
			{ field: "loginName", title: "登录名", width: 120, align: "center" },
			{ field: "state", title: "状态", width: 200, align: "center" }
		];
		var height = 82;
		var params = function (par) {
			var result = {
				pageSize: par.limit,
				pageIndex: (par.offset / par.limit) + 1,
				keyword: $("#SearchKeyWord").val()
			};
			return result;
		};

		$table.initTable(url, columns, height, params, function () { }, false);

        //刷新表格数据
        var refreshTable = function () {
            $table.bootstrapTable("refresh");
        }

        //刷新按钮
        $("#refreshBtn").click(function (e) {
            $table.bootstrapTable("refresh");
        });

        //搜索按钮
        $("#searchBtn").click(function (e) {
            $table.bootstrapTable("refresh");
        });

		//插入按钮
        $("#insertBtn").click(function (e) {
            parent.layer.open({
                type: 2,
                title: "添加登录配置",
                shadeClose: false,
                shade: 0.4,
                area: ["400px", "430px"],
                content: "/organization/staff/logininsert?staffid=" + staffId,
                end: function () {
                	refreshTable();
                }
            });
        });

        //编辑按钮
        $("#editBtn").click(function (e) {
            var selected = $table.bootstrapTable("getSelections");

            if (selected.length > 1) {
                layer.msg("一次只能修改一条数据！", { icon: 5, time: 2000 });
                return;
            }

            if (selected.length == 0) {
                layer.msg("请选择您要修改的数据！", { icon: 5, time: 2000 });
                return;
            }
            editData(selected[0].id);
        });

        //打开编辑窗口
        function editData(id) {
            parent.layer.open({
                type: 2,
                title: "修改管理员",
                shadeClose: false,
                shade: 0.4,
                area: ["400px", "430px"],
                content: "/organization/staff/loginedit?id=" + id,
                end: function () {
                    refreshTable();
                }
            });
        }

        //删除按钮
        $("#deleteBtn").click(function (e) {
            var selected = $table.bootstrapTable("getSelections");
            if (selected.length == 0) {
                layer.msg("请选择您要删除的数据！", { icon: 5, time: 2000 });
                return;
            }

            var arr = [];
            for (var i = 0; i < selected.length; i++) {
                arr.push(selected[i].id);
            }

            var ids = arr.join(",");

            layer.confirm("您确定要删除所选数据吗", {
                btn: ["是的", "取消"] //按钮
            }, function () {
                $.ajax({
                	url: "/organization/staff/logindeleteasync",
                    type: "post",
                    dataType: "json",
                    data: { ids: ids },
                    success: function (data) {
                        //Info,Success,Warning,Error
                        var type = data.type;
                        if (type == 1) {
                            layer.msg(data.content,
                                {
                                    icon: 6, time: 2000
                                },
                                function () {
                                    refreshTable();
                                });
                        } else {
                            layer.msg(data.content, { icon: 5, time: 2000 });
                        }
                    }
                });
            }, function () {
                return;
            });
        });
	</script>
</body>
</html>
